package com.hw.one.peach.da.mongo;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.BasicUpdate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;

import com.alibaba.fastjson.JSONObject;
import com.hw.one.core.mongo.BaseMongo;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
  * @author  sjd 
  * @date 创建时间：2017年7月28日 下午3:12:20 
  * @version 1.0.0
  */
@Repository
public class VOCsMongo extends BaseMongo implements IVOCsMongo {

	@Resource
    MongoTemplate mongoTemplate;
	
	@Override
	public void upload(HashMap<String, Object> data) {
		mongoTemplate.insert(data, "ORI_ITP_VOCS_HOUR-" + String.valueOf(data.get("monitorTime")).substring(0, 4));
	}

	@Override
	public void uploadConvert(HashMap<String, Object> data) {
		mongoTemplate.insert(data, "TRS_ITP_VOCS_HOUR-" + String.valueOf(data.get("monitorTime")).substring(0, 4));
	}

	@Override
	public void importExcel(HashMap<String, Object> data) {
		DBObject obj = new BasicDBObject();
		obj.put("monitorTime", data.get("monitorTime"));
		obj.put("siteCode", data.get("siteCode"));
		Query query = new BasicQuery(obj);
		
		Update update = new BasicUpdate(new BasicDBObject(data));
		mongoTemplate.upsert(query, update, "AUDIT_ITP_VOCS_HOUR-" + String.valueOf(data.get("monitorTime")).substring(0, 4));
	}
}
